package com.bjypc.youth.web.json;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.MessageSource;

import com.bjypc.youth.service.IResearchArticleService;
import com.googlecode.jsonplugin.annotations.JSON;
import com.opensymphony.xwork2.ActionSupport;

public class ImportResearchArticleAction extends ActionSupport {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = -6508572308233342943L;

	private Logger logger = Logger.getLogger(ImportResearchArticleAction.class);
	private MessageSource messageSource;
	private String msg;
	private IResearchArticleService researchArticleService;
	/**
	 * status field to indicate whether operation succeeds
	 */
	private boolean success;
	private boolean failure;

	@Override
	public String execute() throws Exception {
		String downloadPath = ServletActionContext.getServletContext().getRealPath(
				"/download/");
		this.researchArticleService.setWritePath(downloadPath);
		// this.researchArticleService.iterateArticles();
		String articlePath = messageSource.getMessage("ResearchArticlePath",
				null, "c:\\temp\\articles\\", null);
		logger.info("Import articles in  path:" + articlePath);
		this.researchArticleService.iterateArticles(articlePath);
		this.success=true;
		this.msg="文章已经全部导入数据，请刷新页面查看！";
		return SUCCESS;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public boolean isFailure() {
		return failure;
	}

	public void setFailure(boolean failure) {
		this.failure = failure;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	@JSON(serialize = false, deserialize = false)
	public IResearchArticleService getResearchArticleService() {
		return researchArticleService;
	}

	public void setResearchArticleService(
			IResearchArticleService researchArticleService) {
		this.researchArticleService = researchArticleService;
	}

	@JSON(serialize = false, deserialize = false)
	public MessageSource getMessageSource() {
		return messageSource;
	}

	public void setMessageSource(MessageSource messageSource) {
		this.messageSource = messageSource;
	}

}
